package com.zhangfb95.crosschain.plugin.container.java.fabric2.infra.data.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhangfb95.crosschain.plugin.container.java.fabric2.infra.model.mapper.entity.Fabric2BlockEvent;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * @author zhangfubing
 * @since 2023/6/15
 */
@Mapper
public interface Fabric2BlockEventMapper extends BaseMapper<Fabric2BlockEvent> {

    @Update("""
            INSERT fabric2_block_event (chain_name, channel_name) VALUES(#{chainName}, #{channelName})
            """)
    void insert(@Param("chainName") String chainName, @Param("channelName") String channelName);

    @Update("""
            UPDATE fabric2_block_event SET block_number=#{blockNumber}
             WHERE chain_name = #{chainName} AND channel_name = #{channelName} 
            """)
    void setBlockNumber(@Param("chainName") String chainName,
                        @Param("channelName") String channelName,
                        @Param("blockNumber") long blockNumber);

    @Select("""
            SELECT * FROM fabric2_block_event WHERE chain_name = #{chainName} AND channel_name = #{channelName}
            """)
    Fabric2BlockEvent getBlockEvent(@Param("chainName") String chainName, @Param("channelName") String channelName);
}
